package com.cap.bts.crmdp.dealer.remind.dao.impl;

import java.util.List;

import javax.inject.Inject;

import org.apache.log4j.Logger;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.stereotype.Repository;

import com.cap.bts.crmdp.dealer.remind.dao.ITrCustomerGroupDao;
import com.cap.bts.crmdp.dealer.remind.domain.TrCustomerGroup;
import com.cap.bts.framework.common.dao.impl.BaseDaoImpl;
import com.cap.bts.framework.common.exception.AppException;

@Repository("trCustomerGroupDao")
public class TrCustomerGroupDaoImpl extends BaseDaoImpl<TrCustomerGroup, Long> implements ITrCustomerGroupDao {
	
	@Inject
	public TrCustomerGroupDaoImpl(@Value("com.cap.bts.crmdp.dealer.remind.domain.TrCustomerGroup") Class<TrCustomerGroup> clazz) {
		super(clazz);
	}
	
	private static final Logger LOGGER = Logger.getLogger(TrCustomerGroupDaoImpl.class);

	@Override
	public List<TrCustomerGroup> getTrCustomerGroupByDealerIdAndGroupName(Long dealerId, String groupName)
			throws AppException {
		String sql = "select * from tr_customer_group where dealer_id = '" + dealerId
				+ "' and group_id in (select id from tm_raw_group where group_name = '" + groupName + "')";
		return this.getListByNativeQuery(sql);
	}

	@Override
	public List<TrCustomerGroup> getTrCustomerGroup(Long dealerId, Long group_id, Long customer_id)
			throws AppException {
		String sql = "select * from tr_customer_group where dealer_id = '" + dealerId
				+ "' and group_id  = '" + group_id + "' and customer_id = '" + customer_id + "'";
		return this.getListByNativeQuery(sql);
	}

}
